package system.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/15.
 */
public class VoucherDetailDao {
    public static String tableName = "voucher_detail";


    public int insert(List list, int head){
        List<Record> rlist = new ArrayList();
        for(Object obj : list){
            Record r = (Record) obj;
            rlist.add(new Record().setColumns(r).set("voucher_id", head));
        }
        int[] jzpz_details = Db.batchSave(tableName, rlist, 100);
        int sum = 0;
        for(int i : jzpz_details){
            sum += i;
        }
        return sum;
    }

    public List<Record> getListById(int id) {
        return Db.find("select *, (select subject_name from account_subject where subject_id = a.subject_id) subject_name from voucher_detail a where voucher_id = ?", id);
    }

    public boolean deleteById(int voucher_id) {
        return Db.deleteById(tableName, "voucher_id", voucher_id);
    }
}
